package eu.jpereira.trainings.designpatterns.structural.decorator.channel.decorator;

import eu.jpereira.trainings.designpatterns.structural.decorator.channel.SocialChannel;

public class WordCensor extends SocialChannelDecorator {

	private enum TabooWords {
		stupid, fool, donkey, idiot, shit
	}

	public WordCensor() {

	}

	public WordCensor(SocialChannel channel) {
		delegate = channel;
	}

	@Override
	public void deliverMessage(String message) {

		String[] words = message.split(" ");
		StringBuilder builder = new StringBuilder();

		boolean taboo = false;

		for (String word : words) {
			for (TabooWords tb : TabooWords.values()) {
				if (word.equals(tb.toString()) & !taboo) {

					builder.append("### ");
					taboo = true;
				}
			}
			if (!taboo)
				builder.append(word + " ");
			taboo = false;
		}
		message = builder.toString();
		delegate.deliverMessage(message);
	}
}
